package com.syj.usemybatisplus.controller;


import com.syj.usemybatisplus.mapper.QueryMapper;
import com.syj.usemybatisplus.model.vo.request.PageRequest;
import com.syj.usemybatisplus.model.vo.response.BaseResponse;
import com.syj.usemybatisplus.model.vo.response.BaseResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mybatis.plus.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * @ClassName : QueryOracleController
 * @Description :
 * @Author : 石蕴杰
 * @Date: 2020/6/28 20:32
 */
@Controller
@Api(value = "测试查询性能", tags = "测试查询性能")
@RequestMapping("/queryPerformance")
public class QueryOracleController {
    @Autowired
    QueryMapper queryMapper;
    @ApiOperation(value = "mybatis插件方式查询")
    @PostMapping("/queryByMybatis")
    @ResponseBody
    public BaseResponse queryByMybatis(@RequestBody PageRequest pageReques){
        Page page = new Page(900,1000);
        List result;
        System.out.println(page.getPages());
        page.setSearchCount(true);
        long begintime = System.currentTimeMillis();
        result = queryMapper.query1(pageReques,page);
        long endtime=System.currentTimeMillis();

        long costTime = (endtime - begintime);
        System.out.println(page.getTotal());
        System.out.println(page.getPages());
        System.out.println("mybatis插件方式查询耗时: "+costTime+" ms");
        return BaseResponseUtil.success(result);
    }
}
